//
//  HELAppManager.m
//  HandheldELearn
//
//  Created by wsj2015 on 16/7/13.
//  Copyright © 2016年 陈武琦. All rights reserved.
//

#import "HELAppManager.h"
static HELAppManager *appManager;
@implementation HELAppManager


+ (instancetype)sharedAppManger{
    if (!appManager) {
        appManager = [[HELAppManager alloc] init];
    }
    return appManager;
}

+ (HELUser *)userInfo {

   NSDictionary *userInfo = [[NSUserDefaults standardUserDefaults] objectForKey:@"userInfo"];
    if (!userInfo) {
        return nil;
    }
    HELUser *userModel = [HELUser mj_objectWithKeyValues:userInfo];
    return userModel;
}

+ (void)saveUseInfo:(NSDictionary *)userInfo {
    //存储用户信息
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    
    HELUser *user = [HELUser mj_objectWithKeyValues:userInfo];
    [userDefaults setObject:[user mj_keyValues] forKey:@"userInfo"];
  
  
    [userDefaults synchronize];
}

+ (void)removeUserInfo{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults removeObjectForKey:@"userInfo"];
    [userDefaults synchronize];
}

+ (void)saveToken:(NSString *)token{
    //
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    
    [userDefaults setObject:token forKey:APP_TOKEN];
    
    
    [userDefaults synchronize];
}

+ (NSString *)getToken{
    
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSString *token =  [userDefaults objectForKey:APP_TOKEN];
    return token;
}

+ (void)updateBindPhoneStatu:(NSInteger)statue withPhone:(NSString *)phone{
  
   HELUser *user = [self userInfo];
   user.phoneBindStatus = [NSString stringWithFormat:@"%@",@(statue)];
    if (phone) {
        user.mobileNumber = phone;
    }
   
  [self saveUseInfo:[user mj_keyValues]];
    
}

@end
